<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Jerry.DroidBuilder.ThemeEditor.Controls">

  <Style TargetType="{x:Type local:NinePatchControl}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:NinePatchControl}">
          <Grid MinWidth="{Binding DisplayInfo.ImageWidth, RelativeSource={RelativeSource TemplatedParent}}" MinHeight="{Binding DisplayInfo.ImageHeight, RelativeSource={RelativeSource TemplatedParent}}">
            <ItemsControl ItemsSource="{Binding DisplayInfo.Areas, RelativeSource={RelativeSource TemplatedParent}}">
              <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                  <Grid local:NinePatchControl.AttachedDisplayInfo="{Binding DisplayInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:NinePatchControl}}}" />
                </ItemsPanelTemplate>
              </ItemsControl.ItemsPanel>
              <ItemsControl.ItemContainerStyle>
                <Style TargetType="{x:Type ContentPresenter}">
                  <Setter Property="Grid.Row" Value="{Binding Row}" />
                  <Setter Property="Grid.Column" Value="{Binding Column}" />
                </Style>
              </ItemsControl.ItemContainerStyle>
              <ItemsControl.ItemTemplate>
                <DataTemplate>
                  <Rectangle SnapsToDevicePixels="True">
                    <Rectangle.Fill>
                      <ImageBrush ImageSource="{Binding ImageSource}"
                                  RenderOptions.BitmapScalingMode="NearestNeighbor"
                                  Viewbox="{Binding Rect}"
                                  ViewboxUnits="Absolute" />
                    </Rectangle.Fill>
                  </Rectangle>
                </DataTemplate>
              </ItemsControl.ItemTemplate>
            </ItemsControl>
            <ContentPresenter Margin="{Binding DisplayInfo.Padding, RelativeSource={RelativeSource TemplatedParent}}" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>